<template>
    <div>
        <div>
            名称:
            <Input type="text" v-model="searchData.username" style="width: 150px;" clearable />
            活动:
            <Input type="text" v-model="searchData.article_name" style="width: 150px;" clearable />
            时间：
            <Date-picker type="datetimerange" placeholder="开始日期" v-model="searchData.create_time"></Date-picker>

            <Button type="primary" @click="search()" style="margin-left: 10px;">搜索</Button>
            <Button @click="reset()" style="margin-left: 10px;">重置</Button>
            <Button type="info" @click="edit(false, 0)" style="margin-left: 10px;">添加</Button>
        </div>
        <div style="margin-top: 10px;">
            <Table :columns="columns" :data="list" max-height="800" border stripe size="small">
                <template slot-scope="{ row , index}" slot="imgSlot">
                    <show-img :imgUrl="row.qrcode_url"></show-img>
                </template>
                <template slot-scope="{ row , index}" slot="makeSlot">
                    <Button type="info" @click="edit(row, 0)" size="small" style="margin-left: 1px;">编辑</Button>
                    <Button type="error" @click="del(row.id)" style="margin-left: 1px;" size="small">删除</Button>
                </template>
            </Table>
        </div>

        <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize" :currentPage="searchData.page">
        </Paginate>

        <!-- 编辑 -->
        <Modal :title="formItem.id > 0 ? '修改用户' : '添加用户'" v-model="editModal" @on-ok="editModalOk" :width="40"
            :footer-hide="!!formItem.is_detail">
            <Form :model="formItem" :label-width="80">
                <FormItem label="状态" v-if="!formItem.is_detail">
                    <RadioGroup v-model="formItem.status">
                        <Radio label="1" border>待到场</Radio>
                        <Radio label="2" border>已完成</Radio>
                        <Radio label="3" border>已取消</Radio>
                    </RadioGroup>
                </FormItem>
            </Form>
        </Modal>

        <!-- 图片放大-->

    </div>
</template>
  
<script>
import Paginate from "@/components/paginate/paginate.vue";
import ShowImg from '_c/show_img'
export default {
    name: "apply_list",
    components: {
        Paginate,
        ShowImg
    },
    data() {
        return {
            searchData: {
                sort: "desc",
                order_by: "id",
                page: 1,
                limit: 10
            },
            cityList: [],
            // 列表
            columns: [

                {
                    title: '姓名',
                    align: 'center',
                    key: 'username',
                },
                {
                    title: '手机号',
                    align: 'center',
                    key: 'mobile',
                },
                {
                    title: '活动',
                    align: 'center',
                    key: 'article_name',
                },
                {
                    title: '城市',
                    align: 'center',
                    key: 'city_name',
                },

                {
                    title: '状态',
                    align: 'center',
                    key: 'status',
                    render: (h, param) => {
                        let txt = '';
                        let color = '';
                        if (param.row.status == 1) {
                            txt = '待到场';
                            color = 'blue';
                        } else if (param.row.status == 2) {
                            txt = '已完成';
                            color = '#19be6b';
                        } else {
                            txt = '已取消';
                            color = 'red'
                        }
                        return h('div', [
                            h('span', {
                                style: {
                                    color: color
                                }
                            }, txt),
                        ]);
                    },
                },
                {
                    title: '签到时间',
                    align: 'center',
                    key: 'sign_time',
                },
                {
                    title: '下单时间',
                    align: 'center',
                    key: 'create_time',
                },
                {
                    title: '操作',
                    align: 'center',
                    slot: 'makeSlot',
                    width: "180",
                },
            ],
            // 数据
            list: [],
            total: 0,
            // 编辑框
            editModal: false,
            formItem: {},
        }
    },
    methods: {
        // 查询管理员信息
        getList() {
            this.$axios('/admin/active_apply/getList', this.searchData).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        search() {
            this.searchData.page = 1;
            this.getList();
        },
        reset() {
            this.searchData = {
                sort: "desc",
                order_by: "id",
                page: 1,
                limit: 10
            }
            this.getList();
        },
        changePage(page) {
            this.searchData.page = page;
            this.getList();
        },
        changeSize(size) {
            this.searchData.limit = size;
            this.getList();
        },
        edit(row, is_detail) {
            if (row) {
                this.formItem = { ...row };
                this.formItem.status = this.formItem.status + '';
                this.formItem.is_detail = is_detail;
            } else {
                this.formItem = {
                    id: 0,
                    status: "1",
                    is_detail: is_detail
                };
            }
            this.getOpenCityList();
            this.editModal = true;
        },
        editModalOk() {
            this.$axios('/admin/active_apply/save', this.formItem).then(res => {
                this.$Message.success('执行成功');
                this.getList();
            });
        },
        del(id) {
            this.$Modal.confirm({
                title: '删除操作',
                content: "<p>您确定要删除用户吗？</p>",
                onOk: () => {
                    this.$axios('/admin/active_apply/del', { id: id }).then(res => {
                        this.$Message.success('执行成功');
                        this.getList();
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消操作');
                }
            });
        },
        // 获取项目
        getOpenCityList() {
            this.$axios("/admin/config/getCityList").then(res => {
                this.cityList = res;
            });
        },
        showImg(url) {
            this.imgShow = true;
            this.imgShowUrl = url;
        },
    },
    created() {
        this.getList();
    }
}
</script>
<style></style>
  